<template>
  <div class="login-container">
    <h2 class="login-title">系统登录</h2>
    <form @submit.prevent="login">
      <div class="input-group">
        <span class="icon">
          <el-icon><UserFilled /></el-icon>
        </span>
        <input
          type="text"
          v-model="username"
          placeholder="用户名"
          required
        />
      </div>
      <div class="input-group">
        <span class="icon">
          <el-icon><Lock /></el-icon>
        </span>
        <input
          type="password"
          v-model="password"
          placeholder="密码"
          required
        />
      </div>
      <!-- 添加错误提示 -->
      <div v-if="error" class="error-message">{{ error }}</div>
      <button type="submit" class="login-btn">登录</button>
    </form>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus'; // 引入 Element Plus 的消息提示组件
import {checkLogin} from '@/api/account'
import { reactive } from 'vue';

// 定义表单绑定的变量
const username = ref('');
const password = ref('');
const router = useRouter();

const formData = reactive({
  account: '',
  password: ''
})


// 调用层
const login =  async()=>{
  let {code,msg} = await checkLogin(formData);
 
  if(code ==0){
    ElMessage.success(msg)
    router.push('/ht')
  }else{
    ElMessage.error(msg)
  }


 
}
</script>

<style scoped>
/* 全局样式 */
.login-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #2c3e50;
  color: #ecf0f1;
}

/* 标题样式 */
.login-title {
  margin-bottom: 30px;
  font-size: 24px;
  font-weight: bold;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
}

/* 输入框样式 */
.input-group {
  position: relative;
  margin-bottom: 15px;
  width: 300px;
  display: flex;
  align-items: center;
  border: 1px solid #34495e;
  border-radius: 4px;
}

.icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-group input {
  width: 100%;
  padding: 10px 15px 10px 45px;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  color: #ecf0f1;
  background-color: #34495e;
  font-family: Arial, Helvetica, sans-serif;
}

input::placeholder {
  color: #999;
}

.login-btn {
  width: 300px;
  padding: 10px 0;
  font-size: 16px;
  font-weight: bold;
  color: #ecf0f1;
  background-color: #3498db;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.login-btn:hover {
  background-color: #2980b9;
}

.error-message {
  margin-top: 10px;
  color: red;
  font-size: 14px;
}
</style>
